package com.linkage.yninterface.process.processClass;

/**
 * <p>Title: yninterface</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: linkage</p>
 *
 * @author weibo
 * @version 1.0
 */

import java.util.HashMap;
import com.linkage.yninterface.process.*;
import com.linkage.yninterface.db.DB;
import com.linkage.yninterface.util.sysConst;
import com.linkage.yninterface.po.BdKmCardinfo;


public class processoway extends process {

    private DB db = new DB(sysConst.mainDBJNDI);


    public processResult addPortInfo(processPara pp) throws Exception {

        HashMap hmParseObject = pp.getParseObjects();
        BdKmCardinfo bdkc = (BdKmCardinfo) hmParseObject.get("bdkc");
        String type = ((processMapInfo) pp.getParseFields().get(".type")).getValue();
        if (type != null && !type.trim().equals("")) {
            if (type.trim().equals("1")) {
                bdkc.setVlan("-1");
                bdkc.setPort("-1");
            } else if (type.trim().equals("2")) {
                bdkc.setVci("-1");
                bdkc.setVpi("-1");
            } else {
                return new processResult(sysConst.resultCode30,
                                         sysConst.reaultDes30 + ":type");
            }
        } else {
            return new processResult(sysConst.resultCode30,
                                     sysConst.reaultDes30 + ":type");
        }

        if (!db.isExist("select * from MD_KM_OFFICE where oway='" +
                        bdkc.getOway().trim() + "'"))
            return new processResult(sysConst.resultCode21,
                                     sysConst.reaultDes21);

        if (db.isExist("select * from bd_km_cardinfo where nasip='" +
                       bdkc.getNasip() + "' and vpi='" + bdkc.getVpi() +
                       "' and vci='" + bdkc.getVci() + "' and vlan='" +
                       bdkc.getVlan() + "' and port='" + bdkc.getPort() + "'"))
            return new processResult(sysConst.resultCode22,
                                     sysConst.reaultDes22);

        db.insert(bdkc, "BD_KM_CARDINFO");

        return new processResult(sysConst.resultCode0, sysConst.reaultDes0);

    }


    public processResult delPortInfo(processPara pp) throws Exception {

        HashMap hmParseObject = pp.getParseObjects();
        BdKmCardinfo bdkc = (BdKmCardinfo) hmParseObject.get("bdkc");
        String type = ((processMapInfo) pp.getParseFields().get(".type")).getValue();
        if (type != null && !type.trim().equals("")) {
            if (type.trim().equals("1")) {
                bdkc.setVlan("-1");
                bdkc.setPort("-1");
            } else if (type.trim().equals("2")) {
                bdkc.setVci("-1");
                bdkc.setVpi("-1");
            } else {
                return new processResult(sysConst.resultCode30,
                                         sysConst.reaultDes30 + ":type");
            }
        } else {
            return new processResult(sysConst.resultCode30,
                                     sysConst.reaultDes30 + ":type");
        }

        db.execute("delete from BD_KM_CARDINFO where nasip='" +
                   bdkc.getNasip() + "' and vpi='" + bdkc.getVpi() +
                   "' and vci='" + bdkc.getVci() + "' and vlan='" +
                   bdkc.getVlan() + "' and port='" + bdkc.getPort() + "'");

        return new processResult(sysConst.resultCode0, sysConst.reaultDes0);

    }


}

